def stable_jimu(toys, k, x):
    ...
    toys.sort()
    # 统计需要分几个堆，每个堆之间的重量差
    diff_toys = [toys[i] - toys[i - 1] for i in range(1, len(toys))]
    group_diff = []
    for diff_toy in diff_toys:
        if diff_toy > x:
            group_diff.append(diff_toy)

    group_diff.sort()
    # 合并积木堆
    for i in range(k):
        if group_diff != []:
            group_diff[0] -= x
            if group_diff[0] <= x:
                group_diff.pop(0)
        else:
            break
    return len(group_diff) + 1


#  toys = [ 1, 5, 8, 12, 13, 20, 22]
toys = [20, 20, 80, 70, 70, 420, 5, 1, 5, 1, 60, 90]
k = 0
x = 37
res = stable_jimu(toys, k, x)
print(res)
